package concurrent;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;


public class MapTest {
    private static Map<String, Integer> dataMap = new HashMap<String, Integer>();
    
    private static void init() {
        for (int i = 0; i< 30; i++) {
            dataMap.put(Integer.toString(i), i);
        }
    }

    private static void testRemove() {
        System.out.println("before removed size = " + dataMap.size());
        Iterator<Entry<String, Integer>> it = dataMap.entrySet().iterator();
        while(it.hasNext()){
            Entry<String, Integer> entry = it.next();
            if (entry.getValue()%5==0) {
                it.remove();
                //dataMap.remove(entry.getKey());
            }
            
            System.out.println("entry key:" + entry.getKey());
        }
        System.out.println("after removed size = " + dataMap.size());
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
        init();
        testRemove();
    }
}
